<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ThemeManCssClassView.php 320 2008-11-23 07:18:37Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalThemeRecord');
Prado::using('Application.Common.Data.PortalThemeCssClassRecord');
Prado::using('Application.Common.Data.PortalThemeCssClassAttrRecord');

class ThemeManCssClassView extends PortalAdminPage
{
	private $_themeclassid;
	private $_themeid;

	public function onInit($param)
	{
		parent::onInit($param);
		$this->ThemeClassId	= TPropertyValue::ensureInteger($this->Request['id']);
		$this->ThemeId		= TPropertyValue::ensureInteger($this->Request['themeid']);
	}

	public function setThemeClassId($value)
	{
		$this->_themeclassid	= $value;
	}

	public function getThemeClassId()
	{
		return $this->_themeclassid;
	}

	public function setThemeId($value)
	{
		$this->_themeid	= $value;
	}

	public function getThemeId()
	{
		return $this->_themeid;
	}

	public function getDataRows($offset, $rows)
	{
		return $this->DataAccess->createCommand("select * from tblthemecssclassesattr where tcid=" . $this->ThemeClassId . " LIMIT $offset,$rows")->query();
	}

	protected function getRowCount()
    {
        return $this->DataAccess->createCommand("select count(tcid) from tblthemecssclassesattr where tcid=" . $this->ThemeClassId)->queryScalar();
    }

	public function onLoad($param)
	{
		parent::onLoad($param);

		if(!$this->IsPostBack)
		{
			$this->ThemeListCssAttr->VirtualItemCount	= $this->RowCount;
			$this->ThemeListCssAttr->DataSource			= $this->getDataRows(0,$this->ThemeListCssAttr->PageSize);
			$this->ThemeListCssAttr->dataBind();
		}
	}

	public function itemCommand($sender, $param)
	{
	}

	public function pageChanged($sender,$param)
    {
        $this->ThemeListCssAttr->CurrentPageIndex	= $param->NewPageIndex;
		$this->ThemeListCssAttr->DataSource			= $this->getDataRows($this->ThemeListCssAttr->CurrentPageIndex * $this->ThemeListCssAttr->PageSize,$this->ThemeListCssAttr->PageSize);
		$this->ThemeListCssAttr->dataBind();
    }

	public function editItem($sender,$param)
	{
		$this->ThemeListCssAttr->SelectedItemIndex	= -1;
		$this->ThemeListCssAttr->EditItemIndex		= $param->Item->ItemIndex;
		$this->ThemeListCssAttr->DataSource			= $this->getDataRows($this->ThemeListCssAttr->CurrentPageIndex * $this->ThemeListCssAttr->PageSize,$this->ThemeListCssAttr->PageSize);
		$this->ThemeListCssAttr->dataBind();
	}

	public function cancelItem($sender,$param)
	{
		$this->ThemeListCssAttr->SelectedItemIndex	= -1;
		$this->ThemeListCssAttr->EditItemIndex		= -1;
		$this->ThemeListCssAttr->DataSource			= $this->getDataRows($this->ThemeListCssAttr->CurrentPageIndex * $this->ThemeListCssAttr->PageSize,$this->ThemeListCssAttr->PageSize);
		$this->ThemeListCssAttr->dataBind();

	}

	public function updateItem($sender,$param)
	{
		$item	= $param->Item;
		$id		= $this->ThemeListCssAttr->DataKeys[$item->ItemIndex];
		$lsRec	= PortalThemeCssClassAttrRecord::finder()->findByid($id);

		if($lsRec)
		{
			$lsRec->attr	= $item->attr->Text;
			$lsRec->save();
		}

		$this->ThemeListCssAttr->EditItemIndex	= -1;
		$this->ThemeListCssAttr->DataSource		= $this->getDataRows($this->ThemeListCssAttr->CurrentPageIndex * $this->ThemeListCssAttr->PageSize,$this->ThemeListCssAttr->PageSize);
		$this->ThemeListCssAttr->dataBind();
	}

	public function deleteItem($sender, $param)
	{

		$id = $this->ThemeListCssAttr->DataKeys[$param->Item->ItemIndex];
		PortalThemeCssClassAttrRecord::finder()->DeleteByid($id);
		$this->gotoPage('Admin.ThemeManCssClassView',array("id" => $this->ThemeClassId));
	}
}
?>